package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.service.FactoryTeamGroupService;
import com.uwlaser.service.dto.FactoryTeamGroupDto;
import com.uwlaser.service.dto.FactoryTeamGroupQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author huangpan
* @date 2022-12-02
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "班组管理")
@RequestMapping("/api/factoryTeamGroup")
public class FactoryTeamGroupController {

    private final FactoryTeamGroupService factoryTeamGroupService;

    @GetMapping
    @Log("查询班组管理")
    @ApiOperation("查询班组管理")
    @PreAuthorize("@el.check('factoryTeamGroup:list')")
    public ResponseEntity query(FactoryTeamGroupQueryParam query, Pageable pageable){
        return new ResponseEntity<>(factoryTeamGroupService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增班组管理")
    @ApiOperation("新增班组管理")
    @PreAuthorize("@el.check('factoryTeamGroup:add')")
    public ResponseEntity create(@Validated @RequestBody FactoryTeamGroupDto resources){
        return new ResponseEntity<>(factoryTeamGroupService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改班组管理")
    @ApiOperation("修改班组管理")
    @PreAuthorize("@el.check('factoryTeamGroup:edit')")
    public ResponseEntity update(@Validated @RequestBody FactoryTeamGroupDto resources){
        factoryTeamGroupService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除班组管理")
    @ApiOperation("删除班组管理")
    @PreAuthorize("@el.check('factoryTeamGroup:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        factoryTeamGroupService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping("/getTeamOrGroup")
    @Log("获取没有绑定的班组")
    @ApiOperation("获取没有绑定的班组")
    public ResponseEntity getTeamOrGroup() {
        return new ResponseEntity<>(factoryTeamGroupService.getTeamOrGroup(),HttpStatus.OK);
    }

    /*
    @Log("导出班组管理")
    @ApiOperation("导出班组管理")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('factoryTeamGroup:list')")
    public void download(HttpServletResponse response, FactoryTeamGroupQueryParam query) throws IOException {
        factoryTeamGroupService.download(factoryTeamGroupService.queryAll(query), response);
    }*/

}
